var myScroll_left;
var myScroll_right;
function loaded() {
	myScroll_left = new IScroll('#left_Menu', {
		mouseWheel : true,
		click : true
	});
	myScroll_right = new IScroll('#right_Menu', {
		mouseWheel : true,
		click : true
	});
}
document.addEventListener('touchmove', function(e) {
	e.preventDefault();
}, false);

function initHeight() {
	// 菜单框架自动获取高度
	var doc_H = $(document).height();
	$('.Menu_box').height(doc_H);
	var paddingHeight = $("#footer_div").height() + 5;
	$("#scroller2").css({
		"padding-bottom" : paddingHeight + 5
	});
	loaded();
}
function imageLazyInit(){
	$("img.lazy-img").lazyload({
	    skip_invisible : true,
	    container: $("#scroller2")
	});
}

$(document).ready(function() { // tbl切换
			var firstTime ;
			initHeight();
			window.onresize = function() {
				initHeight();
			}
			function initShow() {
				var cateId = $("#selected_class_id").val();
				$(".show_ul").removeClass("show_ul");
				$("#children_of_" + cateId).addClass("show_ul");
			}
			initShow();
			$(".space_footer_div").css("height", $("#footer_div").height());
			$("#search_bar").css("top", $("#header_div").height());
			$(".ot-menu  li").click(function(e,scrollTop,disableFlag) {
				if (firstTime == null) {
					firstTime = new Date().getTime();
				} else {
					var nextTime = new Date().getTime();
					if(nextTime - firstTime < 300){
						return;
					}else{
						firstTime = nextTime;
					}
				}
				//e.stopPropagation();
				var cateId = $(this).attr("cateId");
				$(this).siblings("li").removeClass("active");
				$(this).addClass("active");
				$(".show_ul").removeClass("show_ul");
				$("#children_of_" + cateId).addClass("show_ul");
				myScroll_right.refresh();
				myScroll_right.scrollTo(0, scrollTop?scrollTop:0);
				imageLazyInit();
			});
			$(".goods_link").click(
					function() {
						$.cookie("class", $('.active').index(), {
							expires : 365,
							path : '/',
							domain : '.xinghaoshangcheng.com'
						});
						$.cookie("classY", myScroll_right.y, {
							expires : 365,
							path : '/',
							domain : '.xinghaoshangcheng.com'
						});

						var cateId = $(this).attr("cateId");
						// $(this).attr("href",appPath+"/goods/listByClass/" +
						// cateId+ ".html");
						window.location = appPath
								+ "/goods/findPageResult.html?goodsClassId="
								+ cateId;
					});
			$(".brand_link").click(
					function() {
						$.cookie("class", $('.active').index(), {
							expires : 365,
							path : '/',
							domain : '.xinghaoshangcheng.com'
						});
						$.cookie("classY", myScroll_right.y, {
							expires : 365,
							path : '/',
							domain : '.xinghaoshangcheng.com'
						});
						var brandId = $(this).attr("brandId");
						// $(this).attr("href",appPath+"/goods/listByClass/" +
						// cateId+ ".html");
						window.location = appPath
								+ "/goods/findPageResult.html?brandId="
								+ brandId;
					});
			$("#category_link").click(function() {
				var url = appPath + "/goodsClass/index.html";
				self.location = url;
			});
			$("#cart_link").click(
					function() {
						var url = appPath + "/cart/list.html";
						var cartItemsCookie = $.cookie("cartItems");
						if (cartItemsCookie == undefined
								|| "undefined" == cartItemsCookie
								|| cartItemsCookie == null) {
							cartItemsCookie = "";
						}
						var token = $.cookie("token");
						if (token == undefined || "undefined" == token
								|| token == null) {
							token = "";
						}
						// url+="?cc="+cartItemsCookie+"&token="+token;
						self.location = url;
					});
			$("#mine_link").click(
					function() {
						var url = appPath + "/center/center.html";
						var token = $.cookie("token");
						if (token == undefined || "undefined" == token
								|| token == null) {
							token = "";
						}
						url += "?token=" + token;
						self.location = url;
					});
			if ($.cookie('class') != '' && $.cookie('class') != null&& $.cookie('class') != undefined) {
				var scrollTop = $.cookie('classY');
				$('.ot-menu li').eq($.cookie('class')).trigger('click',[scrollTop,"1"]);
				$.cookie("class", null, {
					expires : -1,
					path : '/',
					domain : '.xinghaoshangcheng.com'
				});
				$.cookie("classY", null, {
					expires : -1,
					path : '/',
					domain : '.xinghaoshangcheng.com'
				});
			}
			imageLazyInit();
		});